# coding:UTF-8
'''
Created on 2015年3月25日

@author: Jeffrey
'''
from django.db import models


class User(models.Model):
    """
    用户信息模型类
    """
    status = models.BooleanField(default=1, max_length=10, help_text="是否可用，0为不可用(但管理员可见)，1为可用")
    nickname = models.CharField(max_length=10, help_text="昵称")
    sex = models.CharField(default='man', max_length=10,help_text="性别")
    email = models.CharField(max_length=25, help_text="邮箱")
    telephone = models.CharField(max_length=15, help_text="家庭电话")
    mobilePhone = models.CharField(max_length=11, help_text="移动电话")
    QQ = models.CharField(max_length=15, help_text="QQ号码")
    WeiBo = models.CharField(max_length=15, help_text="微博帐号")
    WeChat = models.CharField(max_length=25, help_text="微信账号")
    password = models.CharField(max_length=64, help_text="已加密的密文密码")
    loginToken = models.CharField(max_length=64, help_text="登录凭证，为移动app提供")
    introduction = models.CharField(max_length=255, help_text="个人简介")
    level = models.IntegerField(default=0, help_text="用户等级")
    portraitUri = models.CharField(max_length=100, help_text="用户头像")
    lastLoginTime = models.DateTimeField(auto_now=True, help_text="最后的登录时间")
    createTime = models.DateTimeField(auto_now_add=True, help_text="账号创建时间")

    def __unicode__(self):
        return "%s" % u"用户"

    class Meta:
        db_table = 'user'


class Lover(models.Model):
    """
    伴侣关系模型类
    """
    status = models.BooleanField(default=1, max_length=10, help_text="是否可用，0为不可用(但管理员可见)，1为可用")
    firstLover = models.ForeignKey(User, related_name='firstPart' , help_text="伴侣1")
    firstLoverEmail = models.CharField(max_length=25, help_text="伴侣1的邮箱")
    secondLover = models.ForeignKey(User, related_name='secondpart', help_text="伴侣2")
    secondLoverEmail = models.CharField(max_length=25, help_text="伴侣2的邮箱")
    loveOath = models.CharField(max_length=255, help_text="邀请码")
    createTime = models.DateTimeField(auto_now_add=True, help_text="账号创建时间")

    def __unicode__(self):
        return "%s" % u"伴侣"

    class Meta:
        db_table = 'lover'


class Message(models.Model):
    """
    接收到的消息模型类，注：originUser和fromPer不同，originUser是材料的创建者比如文章作者，提问发起者等,fromPer是针对某个材料进行信息分析而向对应的
    接收者发出广播消息，比如系统、评论人或回复者
    """
    status = models.BooleanField(default=True, max_length=10, help_text="是否可用，0为不可用(但管理员可见)，1为可用")
    fromPer = models.ForeignKey(User, related_name="messagefrom", help_text="来源者（不一定是人）")
    toPer = models.ForeignKey(User, related_name="messageto", help_text="接收者")
    type = models.PositiveIntegerField(default=0, help_text="类型,详情配置见youaiwang/webapp_config.py的MSG_TYPE配置参数")
    originUser = models.ForeignKey(User, related_name="messageorigin", help_text="历史材料的创建者，如文章作者")
    originContent = models.CharField(max_length=20, help_text="历史材料的主题内容")
    originUrl = models.CharField(max_length=200, help_text="历史材料的出处url")
    content = models.CharField(max_length=200, help_text="消息主体内容")
    createTime = models.DateTimeField(auto_now_add=True, help_text="创建时间")

    def __unicode__(self):
        return "%s" % u"消息"

    class Meta:
        db_table="message"
